import java.util.concurrent.TimeUnit;

/**
 * Created with IntelliJ IDEA.
 * Description:检测我的线程池,每个任务打印当前执行我的任务的方法
 * User: rei
 * Date: 2025-11-17
 * Time: 15:46
 */
public class Test {
    public static void main(String[] args) throws InterruptedException {
        MyThreadPool myThreadPool = new MyThreadPool(3);

        //通过循环添加任务
        for (int i = 0; i < 10; i++) {
            int taskId = i +1;
            myThreadPool.submit(() ->{
                System.out.println(Thread.currentThread().getName() + "执行" + taskId);
            });

            if (taskId %2 == 0){
                TimeUnit.SECONDS.sleep(1);
            }
        }
    }
    public static void main1(String[] args) {
        MyThreadPool myThreadPool = new MyThreadPool(3);
        myThreadPool.submit(() ->{
            System.out.println(Thread.currentThread().getName());
        });
        myThreadPool.submit(() ->{
            System.out.println(Thread.currentThread().getName());
        });
        myThreadPool.submit(() ->{
            System.out.println(Thread.currentThread().getName());
        });
        myThreadPool.submit(() ->{
            System.out.println(Thread.currentThread().getName());
        });
 myThreadPool.submit(() ->{
            System.out.println(Thread.currentThread().getName());
        });
 myThreadPool.submit(() ->{
            System.out.println(Thread.currentThread().getName());
        });
 myThreadPool.submit(() ->{
            System.out.println(Thread.currentThread().getName());
        });

    }
}
